package com.david.viewtest.view

import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.drawable.AdaptiveIconDrawable
import android.util.AttributeSet
import android.util.Log
import android.view.View
import androidx.core.graphics.drawable.toBitmap
import com.david.viewtest.R

class MoreArrowView: View {
    val paint = Paint()

    val bitmap = (resources.getDrawable(R.mipmap.ic_launcher, null) as AdaptiveIconDrawable).toBitmap()


    var orginWidth = 100
    //init {
        //paint.color = Color.parseColor("#24292b")
        //paint.textSize = 28f
    //}


    private var isExpend = false

    constructor(context: Context, attr: AttributeSet): super(context, attr) {

    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
    }

    override fun onDraw(canvas: Canvas) {
        //super.onDraw(canvas)
        Log.e("more", "width:${width}")
        if (width > 200) {
            //canvas.drawText("释放", (width - textWidth) / 2, (height) / 2 - textHeight / 2, paint)
            //canvas.drawText("查看", (width - textWidth) / 2, (height) / 2 + textHeight, paint)

            isExpend = true
        } else if (orginWidth < width){

            //canvas.save()
            canvas.rotate((width - orginWidth).toFloat(), (bitmap.width/2).toFloat(), (bitmap.height/2).toFloat())
            canvas.drawBitmap(bitmap, 0f, 0f, paint)
            //canvas.restore()


            //canvas.drawText("更多", (width - textWidth) / 2, (height) / 2 + textHeight/ 3, paint)
        } else {
            canvas.drawBitmap(bitmap, 0f, 0f, paint)
        }
    }

    fun getExpend(): Boolean {
        val temp = isExpend
        isExpend = false
        return temp
    }
}